<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Media extends Model
{
    use HasFactory;
    protected $table = 'medias';
    protected $fillable = [
        'member_id',
        'type',
        'source',
        'thumb',
        'filename',
        'size',
        'status'
    ];
    protected $appends = ['video_url','image_url','thumb_url'];

    public function getThumbUrlAttribute()
    {
        return cool_media($this->thumb);
    }

    public function getVideoUrlAttribute()
    {
        $_url = '';
        if($this->type == 'video') {
            $_url = cool_media($this->source);
        }
        return $_url;
    }

    public function getImageUrlAttribute()
    {
        $_url = '';
        if($this->type == "image"){
            return cool_media($this->source);
        }
        return $_url;
    }

    public function member()
    {
        return $this->hasOne(Member::class,'id','member_id');
    }
}
